﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Simple.Admin.Migrations
{
    /// <inheritdoc />
    public partial class add_menuentity1 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "MenuEntityId",
                table: "Menus",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "ParentId",
                table: "Menus",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "TypeEnum",
                table: "Menus",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "AppPermissionMenu",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ProviderType = table.Column<int>(type: "int", nullable: false),
                    ProviderKey = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MenuId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppPermissionMenu", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Menus_MenuEntityId",
                table: "Menus",
                column: "MenuEntityId");

            migrationBuilder.AddForeignKey(
                name: "FK_Menus_Menus_MenuEntityId",
                table: "Menus",
                column: "MenuEntityId",
                principalTable: "Menus",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Menus_Menus_MenuEntityId",
                table: "Menus");

            migrationBuilder.DropTable(
                name: "AppPermissionMenu");

            migrationBuilder.DropIndex(
                name: "IX_Menus_MenuEntityId",
                table: "Menus");

            migrationBuilder.DropColumn(
                name: "MenuEntityId",
                table: "Menus");

            migrationBuilder.DropColumn(
                name: "ParentId",
                table: "Menus");

            migrationBuilder.DropColumn(
                name: "TypeEnum",
                table: "Menus");
        }
    }
}
